package com.qiaofang.applet.service.property.service.dto;

import com.qiaofang.applet.service.member.service.dto.EmployeeListDto;
import com.qiaofang.applet.service.property.domain.PropertyExplain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

@Data
@ApiModel("房源详情DTO")
public class PropertyDetailDto {

    @ApiModelProperty("房源唯一UUID")
    private String propertyUniqueUuid;

    @ApiModelProperty("房源UUID")
    private String propertyUuid;

    @ApiModelProperty("标题")
    private String title;

    @ApiModelProperty("区域名称")
    private String districtName;

    @ApiModelProperty("商圈名称")
    private String areaName;

    @ApiModelProperty("楼盘名称")
    private String estateName;

    @ApiModelProperty("面积")
    private BigDecimal square;

    @ApiModelProperty("类型")
    private String usageTypeName;

    @ApiModelProperty("建房年代")
    private Integer completeYear;

    @ApiModelProperty("装修")
    private String decoration;

    @ApiModelProperty("楼层")
    private String floorRange;

    @ApiModelProperty("是否有电梯")
    private Boolean elevator;

    @ApiModelProperty("是否唯一住房")
    private Boolean onlyHouse;

    @ApiModelProperty("房源编号")
    private String propertyNo;

    @ApiModelProperty("房源描述")
    private String propertyExplain;

    @ApiModelProperty("总层")
    private Integer totalFloor;

    @ApiModelProperty("家具")
    private String furniture;

    @ApiModelProperty("家电")
    private String electric;

    @ApiModelProperty("产权类型")
    private String ownedType;

    @ApiModelProperty("房屋结构")
    private String framework;

    @ApiModelProperty("有无贷款")
    private Boolean credit;

    @ApiModelProperty("委托时间")
    private Date releaseDate;

    @ApiModelProperty("楼盘详情")
    private EstateDetailDto estateDetailDto;

    @ApiModelProperty("房源图片集合")
    private List<PropertyImageDto> propertyImageDtoList;

    @ApiModelProperty("第一经纪人")
    private EmployeeListDto employeeListDto;

    @ApiModelProperty("经纪人集合")
    private List<EmployeeListDto> employeeListDtos;

    @ApiModelProperty(value = "状态", hidden = true)
    private String tradeStatus;
    @ApiModelProperty(value = "朝向", hidden = true)
    private String direction;
    @ApiModelProperty(value = "房")
    private Integer countF;
    @ApiModelProperty(value = "厅", hidden = true)
    private Integer countT;
    @ApiModelProperty(value = "卫", hidden = true)
    private Integer countW;

    @ApiModelProperty("房源核验码")
    private String verifyCode;

    @ApiModelProperty("房源核验二维码")
    private String verifyQrCode;

    @ApiModelProperty("委托编号,委托合同的编号，max：20")
    private String delegateNo;

    @ApiModelProperty("房源核验类型")
    private String verifyType;

    @ApiModelProperty("委托编号(外网)")
    private String consignCode;

    @ApiModelProperty(value = "房源描述集合")
    private List<PropertyExplain> propertyExplainList;

    @ApiModelProperty("房源描述代替房源详情标题")
    private String propertyDepictTitle;

    @ApiModelProperty("小区磐石id")
    private Long estateRockId;

    /**
     * 0125迭代需求，房源描述存在，取其标题代替房源详情标题
     * @return
     */
    public String getPropertyDepictTitle(){
        if (!CollectionUtils.isEmpty(propertyExplainList)) {
            return propertyDepictTitle = propertyExplainList.get(0).getTitle();
        }
        return propertyDepictTitle;
    }

    public String getTitle() {
        if (StringUtils.isBlank(title)) {
            StringBuffer sb = new StringBuffer();
            sb.append(StringUtils.isNotBlank(getEstateName()) ? getEstateName() : "")
                    .append(" ").append(getHouseType());
            title = sb.toString();
        }

        return title;
    }

    public String getHouseType() {
        StringBuffer sb = new StringBuffer();
        sb.append(getCountF() == null ? "0" : getCountF()).append("室")
                .append((getCountT() == null ? "0" : getCountT()) + "厅")
                .append((getCountW() == null ? "0" : getCountW()) + "卫");

        return sb.toString();
    }


    public String getPropertyExplain() {
        if (!CollectionUtils.isEmpty(propertyExplainList) && StringUtils.isNotBlank(propertyExplainList.get(0).getContent())) {
            return propertyExplainList.get(0).getContent();
        }
        String description = String.format("该房源在%s小区，户型是%s，装修是%s，朝向是%s，%s",
                StringUtils.isBlank(estateName) ? " " : estateName,
                getHouseType(),
                StringUtils.isBlank(decoration) ? "暂无" : decoration,
                StringUtils.isBlank(direction) ? "暂无" : direction,
                StringUtils.isBlank(floorRange) ? "" : floorRange);
        return description;
    }

    public String getDelegateNo(){
        if (StringUtils.isNotBlank(consignCode)){
            return consignCode;
        }
        return delegateNo;
    }


}
